package com.example.jee_springboot.entity;

import com.example.jee_springboot.entity.Stu;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class CacheDemo {

    private JdbcTemplate jdbcTemplate;
    @Autowired
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate=jdbcTemplate;
    }

    //@Cacheable(value = "allStus")
    public List<Stu> query() {
        List<Stu> stus = jdbcTemplate.query("SELECT * FROM PUBLIC.STU", (rs, row) -> {
            Stu stu = new Stu();
            stu.setId(rs.getLong("id"));
            stu.setUsername(rs.getString("username"));
            return stu;
        });
        log.debug("--query db--");
        return stus;
    }
}